Don't clone remote repos, use fetch instead
authorAlex Crichton <alex@alexcrichton.com>
Thu, 11 Sep 2014 21:30:13 +0000 (14:30 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 12 Sep 2014 02:05:14 +0000 (19:05 -0700)
When cloning a remote repository, the default behavior of libgit2 is to only
update the local ref that's actually checked out, when we actually would prefer
to update all refs of the remote repo. This removes a call to clone() to a
init_bare() + fetch() which should update all refs accordingly

Closes #565

src/cargo/sources/git/utils.rs
tests/test_cargo_compile_git_deps.rs

index f39b5b7ed71c6ab05d2b51026d28c9d963e79a33..a09e619306285cd1905da2aecd689fe87607a537 100644 (file)
@@ -183,17 +183,9 @@ impl GitRemote {
             try!(rmdir_recursive(dst));
         }
         try!(mkdir_recursive(dst, UserDir));
-        let cfg = try!(git2::Config::open_default());
-        with_authentication(url.as_slice(), &cfg, |f| {
-            let cb = git2::RemoteCallbacks::new()
-                                           .credentials(f);
-            let repo = try!(git2::build::RepoBuilder::new()
-                                                     .bare(true)
-                                                     .hardlinks(false)
-                                                     .remote_callbacks(cb)
-                                                     .clone(url.as_slice(), dst));
-            Ok(repo)
-        })
+        let repo = try!(git2::Repository::init_bare(dst));
+        try!(fetch(&repo, url.as_slice()));
+        Ok(repo)
     }
 }
 
index 0822a7af16aaedd5109436c58564b1b92aa9bf85..cc3acc0a5f3bd0bbefa5b9b9fba28122ea8df81d 100644 (file)
@@ -125,7 +125,7 @@ test!(cargo_compile_git_dep_branch {
     }).assert();
 
     git_project.process("git").args(["checkout", "-b", "branchy"]).exec_with_output().assert();
-    git_project.process("git").args(["branch", "-d", "master"]).exec_with_output().assert();
+    git_project.process("git").args(["checkout", "master"]).exec_with_output().assert();
 
     let project = project
         .file("Cargo.toml", format!(r#"